﻿<Page
    x:Name="pageRoot"
    x:Class="BindingDemo.MainPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:BindingDemo"
    xmlns:common="using:BindingDemo.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Page.Resources>

        <local:ColorConverter x:Key="ColorConverter"/>

        <!-- TODO: Delete this line if the key AppName is declared in App.xaml -->
        <x:String x:Key="AppName">Binding Demo Application</x:String>

        <local:ViewModel x:Key="ViewModel"/>
        <local:UpperCaseConverter x:Key="UpperCaseConverter"/>
    </Page.Resources>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- Back button and page title -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="120"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <TextBlock x:Name="pageTitle" Text="{StaticResource AppName}" Style="{StaticResource HeaderTextBlockStyle}" Grid.Column="1" 
                        IsHitTestVisible="false" TextWrapping="NoWrap" VerticalAlignment="Bottom" Margin="0,0,30,40"/>
        </Grid>

        <Grid Grid.Row="1" 
              Margin="120,30,30,30"
              DataContext="{StaticResource ViewModel}">
            <Grid VerticalAlignment="Top"
              x:Name="FormGrid"
              DataContext="{StaticResource ViewModel}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="400"/>
                    <ColumnDefinition Width="400"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <TextBox Grid.Row="0"
                     Name="FirstName"
                        Grid.Column="0" 
                        Header="First Name"
                        Text="{Binding FirstName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                        Margin="4" Background="{Binding FirstName, Converter={StaticResource ColorConverter}}"></TextBox>
                <TextBox Grid.Row="1"
                         Name="LastName"
                         Background="{Binding LastName, Converter={StaticResource ColorConverter}}"
                         Grid.Column="0"
                         Header="Last Name"
                     Text="{Binding LastName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                       Margin="4"></TextBox>

                <TextBlock
                       Text ="{Binding ElementName=FirstName, Path=Text, Converter={StaticResource UpperCaseConverter}}" Style="{StaticResource BodyTextBlockStyle}"
                       Grid.Column="2" VerticalAlignment="Center" Margin="10,0,0,0"/>
                <TextBlock
                       Text ="{Binding ElementName=LastName, Path=Text, Converter={StaticResource UpperCaseConverter}}" Style="{StaticResource BodyTextBlockStyle}"
                       Grid.Column="2" Grid.Row="1" VerticalAlignment="Center" Margin="10,0,0,0"/>

            </Grid>
        </Grid>
    </Grid>
</Page>
